package com.jlnx.controller.chain;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jlnx.dao.ChainEnterpriseDaoImpl;
import com.jlnx.dao.CoreEnterpriseDaoImpl;
import com.jlnx.dao.EnterpriseDaoImpl;
import com.jlnx.dao.FinanceReqDaoImpl;
import com.jlnx.pojo.ChainEnterprise;
import com.jlnx.pojo.CoreEnterprise;
import com.jlnx.pojo.Enterprise;
import com.jlnx.pojo.FinanceReq;


/*
 * 提交请求
 */
@WebServlet("/FinanceReqController")
public class FinanceReqController extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//获取请求信息
		response.setContentType("charset=UTF-8");
		//设置请求编码模式
    	request.setCharacterEncoding("utf-8");
    	
		String reqName = request.getParameter("reqName");
		String purpose = request.getParameter("purpose");
		String entNo = request.getParameter("entNo");
		String name = request.getParameter("name");
		String entCodeCredit = request.getParameter("entCodeCredit");
		System.out.println("融资金额：" + request.getParameter("reqAmount"));
		BigDecimal reqAmount = new BigDecimal(request.getParameter("reqAmount"));
		String reqTool = request.getParameter("reqTool");
		String product = request.getParameter("product");
		String reply = request.getParameter("reply");
		Date reqDate= new Date();
		String voucherPath = "";
		int reqStatus = 2;
		String reqMassage = "";
		
		FinanceReq financeReq = new FinanceReq(0, reqName, purpose, entNo, name, entCodeCredit, reqAmount, reqTool, product, voucherPath, reqDate, reqStatus, reqMassage, reply);
		System.out.println(financeReq.toString());
		
		//插入融资请求
		FinanceReqDaoImpl dao = new FinanceReqDaoImpl();
		if(dao.insertFinanceReq(financeReq) < 0) {
			request.setAttribute("isRequestSuccess", false);
			request.getRequestDispatcher("/main/financeReq1.jsp").forward(request, response);
			
		}else {
			request.setAttribute("isRequestSuccess", true);
			request.getRequestDispatcher("/main/financeReq1.jsp").forward(request, response);
		}
				
	}

}
